class GifDemo extends egret.DisplayObjectContainer {
  private root: fairygui.GComponent;
  private gloablTransition: fairygui.Transition;
  private closeBtn: fairygui.GObject;

  public constructor() {
    super();
    // 加载皮肤组件
    this.root = fairygui.UIPackage.createObject("Package1", "Component1").asCom;
    this.root.setSize(fairygui.GRoot.inst.width, fairygui.GRoot.inst.height);
    fairygui.GRoot.inst.addChild(this.root);
    // 显示到屏幕之后
    this.once(egret.Event.ADDED_TO_STAGE, this.init, this);
  }

  private init() {
    this.gloablTransition = this.root.getTransition('global');
    this.gloablTransition.play(() => this.removeEvent());
    this.pauseTween();
    this.bindEvent();

    this.closeBtn = this.root.getChild('n63');
    this.closeBtn.touchable = true;
    console.log(this.closeBtn)
    this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
      console.log('结束了')
    }, this);

    // egret.Tween.get(this.closeBtn, { loop: true }).to({ x: 100 }, 200);
  }

  private bindEvent() {
    this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.playTween, this);
    this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.pauseTween, this);
    console.log('事件已经绑定,点击播放全局动画')
  }

  private removeEvent() {
    this.stage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.playTween, this);
    this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this.pauseTween, this);
    console.log('全局动画播放完毕,事件已经移除')
  }

  private playTween() {
    this.gloablTransition.setPaused(false);
  }

  private pauseTween() {
    this.gloablTransition.setPaused(true);
  }

};
